#include <iostream>
#include <memory>
#include <string>
#include "Connection.hpp"
#include "Reacotr.hpp"
#include "IOService.hpp"
#include "Listener.hpp"
#include <functional>
#include "PackageParse.hpp"
using namespace std;
int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        cout << "Usage: " << argv[0] << " port" << endl;
        return 0;
    }
    EnableCout();

    uint16_t port = stoi(argv[1]);
    unique_ptr<Reacotr> svr = make_unique<Reacotr>(); //主服务放前面

    IOService ios(PackageParse::Parse);
    Listener listen(port,ios);

    //添加listenfd连接（也看做是connection）
    svr->AddConnection(listen.Sockfd(),EPOLLIN|EPOLLET,bind(&Listener::Accepter,&listen,placeholders::_1),nullptr,nullptr);
    
    svr->dispatcher();
    return 0;
}